package com.neuedu.javase.collections;

import com.neuedu.entity.Student;

import java.util.*;

/**
 * @auth 金山老师
 * title:   书籍代码
 * creatime: 2022-09-30 10:29
 * 描述 :
 */
public class MyCollections {
    public static void main(String[] args) {

        /**
         * 泛型： 编译期间检查（给编译器使用）
         * //  1.7 类型退到   ArrayList<>()
         */
        ArrayList<Integer> list = new ArrayList();


        list.add(100);
        list.add(5);
        list.add(60);
        list.add(16);
//        list.add("200");
//

        for (Object o : list) {
            System.out.println("o = " + o);
        }

//        list.sort(new Comparator() {
//            @Override
//            public int compare(Object o1, Object o2) {
//                Integer intO1 = (Integer) o1;
//                Integer intO2 = (Integer) o2;
//                return intO1 - intO2;
//            }
//        });

        Collections.sort(list);  //排序的集合List 中的对象数据类型一致

        System.out.println("===========排序之后============");
        for (Object o : list) {
            System.out.println("o = " + o);
        }




        List<User> userList = new ArrayList<>();
        userList.add(new User("张飞",55));
        userList.add(new User("刘备",65));
        userList.add(new User("关羽",60));


        Collections.sort(userList);

        System.out.println("++++++++++++++++++++++++++++");
        for (Object o : userList) {
            System.out.println(o);
        }

        List<Student> stuList = new ArrayList<>();
        stuList.add(new Student("张飞",55));
        stuList.add(new Student("刘备",65));
        stuList.add(new Student("关羽",60));


        Collections.sort(stuList, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }
        });

        System.out.println("++++++++++++++++++++++++++++");
        for (Object o : stuList) {
            System.out.println(o);
        }


    }
}
